package com.refusea.train.controller

import com.refusea.train.domain.entity.User
import com.refusea.train.domain.ex.BizEx
import com.refusea.train.domain.helper.UserUpdateHelper
import com.refusea.train.domain.helper.UserinfoHelper
import com.refusea.train.domain.req.UserUpdateReq
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 * @author Zhang Yan 2024/3/25
 **/
@RestController
@RequestMapping("/api/private/user")
class UserController(
    private val userinfoHelper: UserinfoHelper,
    private val userUpdateHelper: UserUpdateHelper,
) {

    @GetMapping("/info")
    fun getInfo(): User {
        return userinfoHelper.userinfo() ?: throw BizEx.of("请先登录")
    }

    @PostMapping("/update")
    fun update(@RequestBody req: UserUpdateReq) {
        userUpdateHelper.update(req)
    }

}
